<?php 
class Model_Checkin extends Joob_Db_Table{
	public $id;
	public $user_id;
	public $place_id;
	public $time_in;
	public $time_out;
	public $public_id;
	
	protected $key = "id";
	
	protected $db = "checkins";
        
    public function checkIn(){
    	$this->time_in = time();
        return $this->insert('user_id,place_id,time_in, public_id,user_name,place_name');
    }
	
	public function checkout(){
		$this->time_out = time();
		return $this->edit('time_out');
	}
	
	public static function checkCheckedInStatic($user_id,$place_id){
		$checkin = new Model_Checkin();
		$checkin->setOption('user_id',$user_id);
		$checkin->setOption('place_id',$place_id);
		return $checkin->checkCheckedIn();
    }
    
	public function checkCheckedIn() {
        $test = $this->search('user_id=' . $this->user_id . ' and place_id=' . $this->place_id. ' and time_out is null');
        if (sizeof($test) > 0) {
            return true;
        } else {
            return false;
        }
    }
}
?>